Skip to content

fix: strip all accumulated tags in stripTagPrefix to prevent tag accumulation#12

Merged
ualtinok merged 1 commit intocortexkit:masterfrom
tomolom:fix/tag-accumulation
Apr 12, 2026
Merged

fix: strip all accumulated tags in stripTagPrefix to prevent tag accumulation#12
ualtinok merged 1 commit intocortexkit:masterfrom
tomolom:fix/tag-accumulation

Conversation

@tomolom
Copy link
Copy Markdown
Contributor

@tomolom tomolom commented Apr 12, 2026

Summary

Fixes tag accumulation bug where stripTagPrefix only removed a single tag, causing §N§ symbols to accumulate when content is processed multiple times during transform passes, compartment compaction, or message replay.

Changes

Changed TAG_PREFIX_REGEX in tag-content-primitives.ts:

// Before: Only matches ONE tag
const TAG_PREFIX_REGEX = /^§\d+§\s*/;

// After: Matches one or more consecutive tags  
const TAG_PREFIX_REGEX = /^(?:§\d+§\s*)+/;

Problem

The original regex only stripped the outermost tag prefix, leaving previously accumulated tags intact. Each transform pass would prepend a new tag on top of old ones, resulting in unreadable messages like:

§4687§ §4686§ §4685§ ... actual content

Solution

The new regex uses a non-capturing group with + quantifier to match all consecutive tag prefixes at the start of the string. This ensures stripTagPrefix removes all accumulated cruft before prependTag adds a single fresh tag.

Testing

This change maintains backward compatibility - existing single-tag content works identically, and multi-tag content is now properly normalized to a single tag.

Fixes #11

…mulation

The TAG_PREFIX_REGEX was only matching a single tag prefix, causing tags
to accumulate when content is processed multiple times during transform
passes, compartment compaction, or message replay.

Changed the regex from /^§\d+§\s*/ to /^(?:§\d+§\s*)+/ to match one or more
consecutive tags at the start of the string. This ensures stripTagPrefix
removes ALL accumulated tags before prependTag adds a fresh one.

Fixes #11
Copilot AI review requested due to automatic review settings April 12, 2026 18:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a tag prefix normalization bug in the magic-context tagging utilities so repeated transform passes don’t accumulate multiple §<id>§ prefixes on the same content.

Changes:

  • Update the tag-prefix stripping regex to remove all consecutive §<id>§ prefixes at the start of a string (not just the first).
  • Ensure prependTag() consistently results in a single tag prefix even when content has already been tagged multiple times.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ualtinok ualtinok merged commit e76cff1 into cortexkit:master Apr 12, 2026
6 of 7 checks passed
@tomolom tomolom deleted the fix/tag-accumulation branch April 13, 2026 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tag accumulation bug: stripTagPrefix only removes single tag causing excessive §N§ repetition

3 participants